﻿using System;
using System.Collections.Generic;
using UcAsp.Net.IDAL;
using UcAsp.Net.Model;

namespace UcAsp.Net.BLL
{
    public class AdminUserBLL
    {
        private static readonly IAdminUserDAL dal = DALFactory.DataAccess.CreateAdminUser();

        public bool Login(string username, string password, out string msg)
        {
            UcAsp.Net.Model.AdminUser userinfo = dal.Login(username, password);
            if (userinfo == null)
            {
                msg = "用户名不存在";
                return false;
            }
            else
            {
                if (userinfo.UserPassword != password)
                {
                    msg = "登陆密码错误";
                    return false;
                }
                else
                {
                    userinfo.LastLoginTime = userinfo.LoginTime;
                    userinfo.LoginTime = DateTime.Now;
                    dal.Update(userinfo);
                    msg = "登陆成功！";
                    return true;
                }
            }
        }

        public bool Insert(AdminUser user)
        {
            return dal.Insert(user);
        }

        public bool Update(AdminUser user)
        {
            return dal.Update(user);
        }

        public AdminUser GetAdminByUserName(string username)
        {
            return dal.GetAdminByUserName(username);
        }

        public List<AdminUser> Select()
        {
            return dal.Select();
        }
    }
}